import pygame
import os

class CellVisuals(pygame.sprite.Sprite):
    '''
    The CellVisuals Object is responsible for rendering the floor of each cell.
    It uses the tile image set in the Config
    It takes a string parameter (you might use it to display the coordinates of
    a cell on the cell itself)
    '''

    def __init__(self,x,y, string, config):
        # Call the parent's constructor
        pygame.sprite.Sprite.__init__(self)

        self.tile_size = config.tile_size

        # Make the surface the size of a tile
        self.image = pygame.Surface([self.tile_size, self.tile_size])

        # The coordinates passed in are grid coordinates so we have
        # to multiply by the tilesize to get the pixel coords
        self.rect = self.image.get_rect()
        self.rect.top = y * self.tile_size
        self.rect.left = x * self.tile_size

        # If an image is set in the Config, blit it onto the surface of the cell
        # (otherwise the surface will just be black)
        if config.cell_image != None:
            self.image.blit(config.cell_image,(0,0))

        # If a string was specified, draw the text onto the middle of the cell,
        # on top of the image
        if len(string) > 0:
            font = pygame.font.Font(None, 12)
            text = font.render(string, 1, config.Colors['text_color'])
            text_pos = text.get_rect(centerx = self.tile_size / 2,
                                     centery = self.tile_size / 2)
            self.image.blit(text, text_pos)




